import 'package:distribution_mall_flutter/constant/cf_constant.dart';
import 'package:distribution_mall_flutter/constant/constant.dart';
import 'package:distribution_mall_flutter/generated/l10n.dart';
import 'package:distribution_mall_flutter/provider/order/order_list.dart';
import 'package:distribution_mall_flutter/router/route_utils.dart';
import 'package:distribution_mall_flutter/utils/common_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:popover/popover.dart';

class OrderMore extends ConsumerWidget {
  final String distributionOrderId;
  final bool goBack;
  final double width;
  final double arrowDxOffset;
  final Function()? callback;
  const OrderMore(
      {super.key,
      required this.distributionOrderId,
      this.goBack = false,
      this.arrowDxOffset = -30,
      this.callback,
      this.width = 100});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    return Container(
        width: width,
        height: 32,
        alignment: Alignment.centerLeft,
        child: GestureDetector(
          onTap: () {
            CommonPopWidget.showPop(
                context: context,
                direction: PopoverDirection.top,
                arrowDxOffset: arrowDxOffset,
                bodyBuilder: (context) {
                  return Center(
                    child: GestureDetector(
                      onTap: () {
                        ref.read(orderListProvider.notifier).deleteOrder({
                          'distributionOrderId': distributionOrderId
                        }).then((bol) {
                          if (bol && goBack) {
                            RouteUtils.back();
                            if (callback is Function) {
                              callback!();
                            }
                          }
                        }).whenComplete(() {
                          RouteUtils.back();
                        });
                      },
                      child: Text(
                        S.current.delete,
                        style: const TextStyle(
                            fontSize: FontConstant.f13,
                            color: ColorConstant.black51),
                      ),
                    ),
                  );
                });
          },
          child: Text(
            S.of(context).more,
            style: const TextStyle(
              color: ColorConstant.black89,
              fontSize: FontConstant.f13,
            ),
          ),
        ));
  }
}
